1 // Equipo Poncho, Carriel y Ruana
2 // Accepted on UVa - This is the fastest implementation I could get.
23 template <class T
> string
toStr(const T
&x
)
24 { stringstream s
; s
<< x
; return s
.str(); }
25 template <class T
> int toInt(const T
&x
)
26 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
28 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
30 #define D(x) cout << #x " = " << (x) << endl;
32 const double EPS
= 1e-9;
34 int cmp(double x
, double y
= 0, double tol
= EPS
) {
35 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
39 #define MAXBUFF (1<<18)
40 char buffer
[MAXBUFF
], *p
= buffer
+MAXBUFF
;
41 char buffer2
[MAXBUFF
], *p2
= buffer2
;
43 inline char read_char() {
44 if( p
== buffer
+MAXBUFF
) {
45 fread( buffer
, 1, MAXBUFF
, stdin
);
51 inline int read_int() {
53 while( !isdigit(c
= read_char()) );
55 while( isdigit(c
= read_char()) ) ret
= ret
* 10 + c
-'0';
60 fwrite( buffer2
, 1, p2
-buffer2
, stdout
);
64 inline void write( char c
) {
65 if( p2
== buffer2
+MAXBUFF
) {
66 fwrite( buffer2
, 1, MAXBUFF
, stdout
);
74 const int MAXBASES
= 105, oo
= 1 << 28;
81 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
86 for (int i
= 0; i
< B
; ++i
) {
87 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
88 if (dp
[mask
] >= oo
) continue;
89 int new_mask
= mask
| bases
[i
];
90 int score
= dp
[mask
] + 1;
91 if (score
< dp
[new_mask
]) dp
[new_mask
] = score
;
100 if (B
== 0 and D
== 0) break;
101 for (int i
= 0; i
< B
; ++i
) {
104 int k
= IO::read_int();
106 int x
= IO::read_int(); x
--;
107 bases
[i
] |= (1 << x
);
111 for (int j
= 0; j
< D
; ++j
) {
113 int k
= IO::read_int();
115 int x
= IO::read_int(); x
--;
120 if (ans
>= oo
) ans
= 0;
123 if (j
+ 1 < D
) printf(" ");